/**
 * 初始化商品属性值详情对话框
 */
var ColModelInfoDlg = {
    colModelInfoData : {}
};

/**
 * 清除数据
 */
ColModelInfoDlg.clearData = function() {
    this.colModelInfoData = {};
}

/**
 * 设置对话框中的数据
 *
 * @param key 数据的名称
 * @param val 数据的具体值
 */
ColModelInfoDlg.set = function(key, val) {
    this.colModelInfoData[key] = (typeof val == "undefined") ? $("#" + key).val() : val;
    return this;
}

/**
 * 设置对话框中的数据
 *
 * @param key 数据的名称
 * @param val 数据的具体值
 */
ColModelInfoDlg.get = function(key) {
    return $("#" + key).val();
}

/**
 * 关闭此对话框
 */
ColModelInfoDlg.close = function() {
    parent.layer.close(window.parent.ColModel.layerIndex);
}

/**
 * 收集数据
 */
ColModelInfoDlg.collectData = function() {
    this
    .set('id')
    .set('tableName')
    .set('colName')
    .set('entityName')
    .set('indexName')
    .set('colSimpleType')
    .set('colLabel')
    .set('key')
    .set('gen')
    .set('hidden')
    .set('width')
    .set('align')
    .set('search')
    .set('resizable')
    .set('fixed')
    .set('sortable')
    .set('searchOptionsSopt')
    .set('searchOptionsExtra')
    .set('formatter')
    .set('unformat')
    .set('fdSelect')
    .set('multiple')
    .set('refTable')
    .set('refKeyField')
    .set('refDescField')
    .set('refFilter')
    .set('sDataurl')
    .set('eDataurl')
    .set('editable')
    .set('editOptionsExtra')
    .set('genRefVar')
    .set('colSetting')
    .set('sortNum')
    .set('created')
    .set('modified');
}

/**
 * 提交添加
 */
ColModelInfoDlg.addSubmit = function() {

    this.clearData();
    this.collectData();

    //提交信息
    var ajax = new $ax(Feng.ctxPath + "/colModel/add", function(data){
        Feng.success("添加成功!");
        $("#refresh_ColModel", window.parent.document).click();	//重新载入 
        ColModelInfoDlg.close();
    },function(data){
        Feng.error("添加失败!" + data.responseJSON.message + "!");
    });
    ajax.set(this.colModelInfoData);
    ajax.start();
}

/**
 * 提交修改
 */
ColModelInfoDlg.editSubmit = function() {

    this.clearData();
    this.collectData();

    //提交信息
    var ajax = new $ax(Feng.ctxPath + "/colModel/update", function(data){
        Feng.success("修改成功!");
        $("#refresh_ColModel", window.parent.document).click();	//重新载入 
        ColModelInfoDlg.close();
    },function(data){
        Feng.error("修改失败!" + data.responseJSON.message + "!");
    });
    ajax.set(this.colModelInfoData);
    ajax.start();
}

/**
 * 控件处理
 */
$(document).ready(function() {
	var bdata =  [{id: false,text: '否'},{id: true,text: '是'}];
	$("#key").select2({
		tags: false,
		data: bdata,
	});
	$('#key').val($("#key").val()).trigger('change');
	
	$("#gen").select2({
		tags: false,
		data: bdata,
	});
	$('#gen').val($("#gen").val()).trigger('change');
	
	$("#hidden").select2({
		tags: false,
		data: bdata,
	});
	$('#hidden').val($("#hidden").val()).trigger('change');
	
	$("#search").select2({
		tags: false,
		data: bdata,
	});
	$('#search').val($("#search").val()).trigger('change');
	
	$("#resizable").select2({
		tags: false,
		data: bdata,
	});
	$('#resizable').val($("#resizable").val()).trigger('change');
	
	$("#fixed").select2({
		tags: false,
		data: bdata,
	});
	$('#fixed').val($("#fixed").val()).trigger('change');
	
	$("#sortable").select2({
		tags: false,
		data: bdata,
	});
	$('#sortable').val($("#sortable").val()).trigger('change');
	
	$("#fdSelect").select2({
		tags: false,
		data: bdata,
	});
	$('#fdSelect').val($("#fdSelect").val()).trigger('change');
	
	$("#multiple").select2({
		tags: false,
		data: bdata,
	});
	$('#multiple').val($("#multiple").val()).trigger('change');
	
	$("#editable").select2({
		tags: false,
		data: bdata,
	});
	$('#editable').val($("#editable").val()).trigger('change');
	
	$("#genRefVar").select2({
		tags: false,
		data: bdata,
	});
	$('#genRefVar').val($("#genRefVar").val()).trigger('change');
	
	datePick($("#created")[0]);
	
	datePick($("#modified")[0]);
	
});

